package com.itheima.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.admin.dto.AdChannelDto;
import com.itheima.admin.mapper.AdChannelMapper;
import com.itheima.admin.pojo.AdChannel;
import com.itheima.admin.service.AdChannelService;
import com.itheima.common.vo.PageResultVo;
import org.springframework.stereotype.Service;

@Service
public class AdChannelServiceImpl extends ServiceImpl<AdChannelMapper,AdChannel> implements AdChannelService {
    /**
     * 频道分页查询
     * @param adChannelDto 接收查询条件参数
     * @return 返回分页查询的结果
     */
    @Override
    public PageResultVo findList(AdChannelDto adChannelDto) {
        //1.创建分页查询的对象IPage
        IPage<AdChannel> pageInfo = new Page<>(adChannelDto.getPage(),adChannelDto.getSize());
        //2、构建查询条件对象
        LambdaQueryWrapper<AdChannel> lwq = new LambdaQueryWrapper<>();
        //2.1、根据name进行模糊查询
        lwq.like(StringUtils.isNotEmpty(adChannelDto.getName()),AdChannel::getName,adChannelDto.getName());
        //2.3、更具状态匹配查询
        lwq.eq(adChannelDto.getStatus()!=null,AdChannel::getStatus,adChannelDto.getStatus());
        //3.执行分页查询
        IPage<AdChannel> page = page(pageInfo, lwq);
        return PageResultVo.pageResult(pageInfo.getPages(),pageInfo.getSize(),pageInfo.getTotal(),pageInfo.getRecords());
    }
}
